home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / language / sozobon1.zoo / sys / minimum.h next >
C/C++ Source or Header  |  1990-11-16  |  1KB  |  67 lines

  1. /*
  2.  *
  3.  * DO NOT INCLUDE THIS FILE IF YOU USE ARGC/ARGV OR STANDARD I/O AT ALL!!
  4.  *
  5.  * This header file defines _initarg() and _main() functions, that replace
  6.  * the ones in the standard library.  With these functions, none of the
  7.  * standard i/o functions normally linked into a program will be referenced,
  8.  * and the command line arguments will not be parsed.
  9.  *
  10.  * However... if you REALLY need arguments, but still want a teeny tiny
  11.  * (non-portable) program, you can use a main() like this...
  12.  *
  13.  *    #include <sys\minimum.h>
  14.  *
  15.  *    main()
  16.  *        {
  17.  *        register char *p, *q, *t;
  18.  *    
  19.  *        t = (p + _cmdlen);
  20.  *        *t = '\0';
  21.  *        p = _cmdline;
  22.  *        while(p < t)
  23.  *            {
  24.  *            while(*p == ' ')
  25.  *                ++p;
  26.  *            if(*p == '\0')
  27.  *                break;
  28.  *            for(q = p; (*q && (*q != ' ')); ++q)
  29.  *                ;
  30.  *            *q = '\0';
  31.  *            process(p);    <-- insert real operation here
  32.  *            p = q + 1;
  33.  *            }
  34.  *        }
  35.  */
  36.  
  37. #ifndef MINI_H
  38. #define    MINI_H
  39.  
  40. extern int    _argc;
  41. extern char    **_argv;
  42. extern char    *_envp;
  43.  
  44. char    *_cmdline;    /* make command line image globally available */
  45. int    _cmdlen;    /* make it's length global also */
  46.  
  47. _initargs(cmdline, cmdlen)
  48.     register char *cmdline;
  49.     register int cmdlen;
  50.     {
  51.     register int i = cmdlen;
  52.     char *sbrk(), *strncpy();
  53.  
  54.     _cmdline = strncpy(sbrk((i + 2) & ~1), cmdline, cmdlen);
  55.     _cmdline[_cmdlen = cmdlen] = '\0';
  56.     }
  57.  
  58. _main()
  59.     {
  60.     main(_argc, _argv, _envp);
  61.     _exit(0);
  62.     }
  63.  
  64. #define    exit(code)    _exit(code)    /* no stdio, no cleanup needed */
  65.  
  66. #endif
  67.